package ynu.lcy.elememicroserviceuserauthservice9091.controller.inner;

import com.auth0.jwt.interfaces.DecodedJWT;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ynu.lcy.elememicroserviceserviceclient.service.AuthFeignClient;
import ynu.lcy.elememicroserviceuserauthservice9091.service.AuthenticationService;


import javax.annotation.Resource;

import static ynu.lcy.elememicroservicecommon.constant.CommonConstant.ACCESS_TOKEN;

/**
 *
 * 这是一个内部接口，用于获取登录用户的信息，前端不可调用
 * */

@RestController
@RequestMapping("/auth/inner")
public class AuthInnerController implements AuthFeignClient {

    @Resource
    private AuthenticationService service;

    /**
     * 内部获取登录用户信息
     * */
    @GetMapping("/getLoginUser")
    @Override
    public Long getLoginUser(@RequestParam("token") String token) {
        DecodedJWT decodedJWT = service.validateToken(token, ACCESS_TOKEN);
        String s = decodedJWT.getAudience().get(1);
        return Long.parseLong(s);
    }
}
